package com.example.demo.java;

import java.util.Stack;

public class PaiLieZuHe {

    public static Stack<Integer> stack = new Stack<Integer>();

    public static void main(String[] args) {
        /** 排列组合 https://www.cnblogs.com/zzlback/p/10947064.html */
        int shu[] = {1,2,3,4};
        f(shu,4,0);

//        stack.add(1);
//        stack.add(2);
//        stack.pop();
//        System.out.println(stack);
    }

    /**
     * @param shu  待选择的数组
     * @param targ 要选择多少个次
     * @param cur  当前选择的是第几次
     */
    private static void f(int[] shu, int targ, int cur) {
        // TODO Auto-generated method stub
        if (cur == targ) {
            System.out.println("符合获取次数4位组合可重复：" + stack);
            return;
        }

        for (int i = 0; i < shu.length; i++) {
//            if (!stack.contains(shu[i])) {
            stack.add(shu[i]);
            f(shu, targ, cur + 1);
            stack.pop();
//            }
        }
    }

}
